<?php
// +----------------------------------------------------------------------
// | OneKeyAdmin [ Believe that you can do better ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2023 http://onekeyadmin.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: MUKE <513038996@qq.com>
// +----------------------------------------------------------------------
namespace plugins\pay\index\controller;

use think\facade\View;
use app\index\BaseController;
use plugins\pay\addons\Alipay;
use plugins\pay\addons\Wechat;
/**
 * 异步通知（标准结构）
 */
class Notify extends BaseController
{
    public function alipay()
    {
    	$file  = plugin_path() . 'pay/log.txt';
        $input = input();
        File::create($file, $input);
        if (empty($input['out_trade_no'])) {
            echo 'fail';
        }
        $result = Alipay::query($input['out_trade_no']);
    	if ($result['status'] != 'success') {
    		echo 'fail';
    	}
        // 	业务逻辑
    	echo 'success';
    }

    public function wechat()
    {
    	$file  = plugin_path() . 'pay/log.txt';
        $xml   = json_encode(simplexml_load_string(input(), 'SimpleXMLElement', LIBXML_NOCDATA));
        $input = json_decode($xml, true);
        File::create($file, $input);
        if (empty($input['out_trade_no'])) {
            echo '<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[订单不存在]]></return_msg></xml>';
        }
    	$result = Wechat::query($input['out_trade_no']);
    	if ($result['status'] != 'success') {
    	    echo '<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[订单不存在]]></return_msg></xml>';
    	}
        // 	业务逻辑
    	echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
    }
}